package com.recruit.g1.resume.service.impl;

import com.recruit.g1.common.response.JsonResult;
import com.recruit.g1.pojo.resume.dto.ResumeCreate;
import com.recruit.g1.pojo.resume.entity.Resume;
import com.recruit.g1.pojo.resume.vo.ResumeInfoVO;
import com.recruit.g1.resume.mapper.ResumeMapper;
import com.recruit.g1.resume.service.ResumeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ResumeServiceImpl implements ResumeService {
    @Autowired
    ResumeMapper resumeMapper;
    @Override
    public void createResume(ResumeCreate resumeCreate) {
        log.debug("进入简历创建：{}" , resumeCreate);
        Resume resume = new Resume();
        resume.setUserId(1);
        BeanUtils.copyProperties(resumeCreate,resume,"id");
        resumeMapper.insert(resume);
    }

    @Override
    public List<ResumeInfoVO> selectByUserId(Long userId) {
        log.debug("进入查询用户简历：{}" , userId);
        List<ResumeInfoVO> list=resumeMapper.selectByUserId(userId);
        return list;
    }

    @Override
    public void edit(ResumeCreate resumeCreate) {
        log.debug("进入修改用户简历：{}" , resumeCreate);
        Resume resume = new Resume();
        BeanUtils.copyProperties(resumeCreate,resume);
        resumeMapper.updateById(resume);

    }


    @Override
    public JsonResult deleteById(Long id) {

        int result = resumeMapper.deleteById(id);

        if (result==1){
            return JsonResult.ok(result);
        }
        return JsonResult.fail("删除失败");
    }


}
